package com.gufe.service.user.impl.mp.quiz;


import com.gufe.entity.quiz.Competition;
import com.gufe.mapper.user.mp.quiz.CompetitionMapper;
import com.gufe.service.user.mp.quiz.CompetitionService;
import com.gufe.vo.quiz.CompetitionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompetitionServiceImpl implements CompetitionService {

    @Autowired
    private CompetitionMapper competitionMapper;

    @Override
    public List<CompetitionVO> getAllCompetitions() {
        List<CompetitionVO> competitions = competitionMapper.findAll();
        List<CompetitionVO> competitionVOs = new ArrayList<>();
        for (CompetitionVO competition : competitions) {
            CompetitionVO vo = new CompetitionVO();
            vo.setId(competition.getId());
            vo.setPeriod(competition.getPeriod());
            vo.setDescription(competition.getDescription());
            vo.setCoverImageUrl(competition.getCoverImageUrl());
            vo.setCreatedAt(competition.getCreatedAt());
            competitionVOs.add(vo);
        }
        return competitionVOs;
    }

    @Override
    public CompetitionVO getCompetitionById(Long id) {
        Competition competition = competitionMapper.findById(id);
        if (competition != null) {
            CompetitionVO vo = new CompetitionVO();
            vo.setId(competition.getId());
            vo.setPeriod(competition.getPeriod());
            vo.setDescription(competition.getDescription());
            vo.setCoverImageUrl(competition.getCoverImageUrl());
            vo.setCreatedAt(competition.getCreatedAt());
            return vo;
        }
        return null;
    }
}